//--------------------------------------------------------------------------------------
// File: SimpleSample.fx
//
// The effect file for the SimpleSample sample.  
// 
// Copyright (c) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------


//--------------------------------------------------------------------------------------
// Global variables
//--------------------------------------------------------------------------------------
cbuffer cb0
{
	float    g_fTime;                   // App's time in seconds
	float4x4 g_mWorld;                  // World matrix for object
	float4x4 g_mWorldViewProjection;    // World * View * Projection matrix
	float g_maxZ = 400.0;
	float g_minZ = -50.0;
}

//--------------------------------------------------------------------------------------
// Vertex shader input structure
//--------------------------------------------------------------------------------------
struct VS_INPUT
{
    float3 Position   : POSITION;   // vertex position 
};

//--------------------------------------------------------------------------------------
// Vertex shader output structure
//--------------------------------------------------------------------------------------
struct VS_OUTPUT
{
    float4 Position   : SV_Position;   // vertex position 
	float4 Pos3d      : POSITION;
	float4 Color      : COLOR;
};


//--------------------------------------------------------------------------------------
// This shader computes standard transform and lighting
//--------------------------------------------------------------------------------------
VS_OUTPUT RenderSceneVS( VS_INPUT In )
{
	VS_OUTPUT Output;
	float4 pos = float4(In.Position, 1.0f);
	
	Output.Pos3d = pos;

	//float c = ( In.Position.z - g_minZ ) / g_maxZ;
    //Output.Color = float4( 1 * (c-0.5) * (c-0.5), 4 * (c-0.5) * (c-0.5), c, 1 );
    
    Output.Position = mul(pos, g_mWorldViewProjection);
    return Output;    
}

//--------------------------------------------------------------------------------------
// This shader outputs the pixel's color by modulating the texture's
// color with diffuse material color
//--------------------------------------------------------------------------------------
float4 RenderScenePS( VS_OUTPUT In ) : SV_Target
{ 
	
	float c = ( In.Pos3d.z - g_minZ ) / g_maxZ;
    return float4( 1 * (c-0.5) * (c-0.5), 4 * (c-0.5) * (c-0.5), c, 1 );
    
    //return In.Color;
}


//--------------------------------------------------------------------------------------
// Depth buffer
//--------------------------------------------------------------------------------------
DepthStencilState EnableDepth
{
    DepthEnable = TRUE;
    DepthWriteMask = ALL;
    DepthFunc = LESS_EQUAL;
};


//--------------------------------------------------------------------------------------
// Renders scene 
//--------------------------------------------------------------------------------------
technique10 RenderScene
{
    pass P0
    {
		SetDepthStencilState(EnableDepth, 0);       
		SetVertexShader( CompileShader( vs_4_0, RenderSceneVS() ) );
        SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_4_0, RenderScenePS() ) );
    }
}

